package com.sacfa.jframes;

import java.awt.Toolkit;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.sacfa.commons.beans.Usuario;
import com.sacfa.commons.utilities.Utilities;
import com.sacfa.panels.MenuAdministrador;
import com.sacfa.panels.MenuFinanzas;
import com.sacfa.panels.MenuInventario;
import com.sacfa.panels.MenuRRHH;

@SuppressWarnings("serial")
public class Principal extends JFrame {
	public JPanel contentPane;
	private static Principal instance = null;
	
	private Principal() {
		setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
		setSize(100, 100);
		setResizable(false);
		setTitle("Bienvenido " + Usuario.getUsuarioActivo() + " a SACFA");
		setLocationRelativeTo(null);
		setIconImage(Toolkit.getDefaultToolkit().getImage(Utilities.obtenerClassPath() + "resources\\images\\icon.png"));
		addWindowListener(new java.awt.event.WindowAdapter(){
			public void windowClosing(WindowEvent e){
				Utilities.cerrarVentana();
	        }
	    });
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		if(Usuario.getTipo().equals("Administrador")){
			MenuAdministrador menuAdministrador = new MenuAdministrador();
			setSize(menuAdministrador.getWidth(), menuAdministrador.getHeight());
			contentPane.add(menuAdministrador);
		} else if(Usuario.getTipo().equals("Finanzas")){
			MenuFinanzas menuFinanzas = new MenuFinanzas();
			setSize(menuFinanzas.getWidth(), menuFinanzas.getHeight());
			contentPane.add(menuFinanzas);
		} else if(Usuario.getTipo().equals("RRHH")){
			MenuRRHH menuRRHH = new MenuRRHH();
			setSize(menuRRHH.getWidth(), menuRRHH.getHeight());
			contentPane.add(menuRRHH);
		} else if(Usuario.getTipo().equals("Inventario")){
			MenuInventario menuInventario = new MenuInventario();
			setSize(menuInventario.getWidth(), menuInventario.getHeight());
			contentPane.add(menuInventario);
		} 
	}
	
	public static Principal getInstance(){
		if(instance == null){
			instance = new Principal();
		}
		return instance;
	}
}
